/**
 * @author Marcel Heinrichs
 *
 */
import java.util.*;
import java.awt.Point;

public class Map {
	// Attribute
	private int sizeX;
	private int sizeY;
	private Point exit;
	private List<Obstacle> obstacles = new ArrayList<Obstacle>();
	// Methoden
	public Map(int sizeX, int sizeY, Point exit) {
		this.sizeX = sizeX;
		this.sizeY = sizeY;
		this.exit = exit;
	}
	public boolean isBlocked(Point pos) {
		Iterator<Obstacle> iter = this.obstacles.iterator();		
		while(iter.hasNext()) {
			Obstacle obs = iter.next();
			// Überprüfe X-Reihe
			if(obs.getPosA().x < obs.getPosB().x)
				if(pos.x >= obs.getPosB().x && pos.x <= obs.getPosA().x)
					return true;
			else
				if(pos.x >= obs.getPosA().x && pos.x <= obs.getPosB().x)
					return true;
			// Überprüfe Y-Reihe
			if(obs.getPosA().y < obs.getPosB().y)
				if(pos.y >= obs.getPosB().y && pos.y <= obs.getPosA().y)
					return true;
			else
				if(pos.y >= obs.getPosA().y && pos.y <= obs.getPosB().y)
					return true;
		}
		if(pos.equals(exit) || ((pos.x > 0 && pos.x < this.sizeX) && (pos.y > 0 && pos.y < this.sizeY)))
			return false;
		else 
			return true;
	}
	public void addObstacle(Obstacle obs) {	this.obstacles.add(obs); }
	public int getSizeX() { return this.sizeX; }
	public int getSizeY() { return this.sizeY; }
}
